/*
 * 
 * Version 1.00
 * 
 * Created on 2007-6-4
 * Encoding GB2312
 */
package net.comm.oper.service.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.List;
import java.util.Vector;

import net.comm.common.GlbFinal;
import net.comm.common.ReturnMessage;
import net.comm.common.common;
import net.comm.file.service.impl.FilesServiceImpl;
import net.comm.file.web.form.FilesForm;
import net.comm.friend.db.DbFriendService;

import net.comm.message.service.impl.MessageServiceImpl;
import net.comm.message.service.impl.MsgcontServiceImpl;
import net.comm.message.web.form.MessageForm;
import net.comm.message.web.form.MsgcontForm;
import net.comm.oper.bean.BaseNotAdv;
import net.comm.oper.db.DbNotAdvService;
import net.comm.oper.db.NotAdvServiceSqlMysql;
import net.comm.oper.web.form.NotAdvForm;
import net.comm.page.PageCtr;
import net.comm.param.service.impl.SequenceMgr;

import net.comm.shequ.web.form.JgShenqingForm;
import net.comm.user.service.impl.UsersServiceImpl;
import net.comm.user.web.form.UsersForm;
import net.comm.util.DatetimeUtil;
import net.comm.util.DbcpPool;
import net.comm.util.StringUtil;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;
import org.sakaiproject.db.impl.BasicSqlService;


/**
 *
 * @author hcgong(hcgong@sina.com)
 * @version 1.0
 * @date 2007-6-4
 */
public class NotAdvServiceImpl {

	static Logger logger = Logger.getLogger(NotAdvServiceImpl.class.getName());

	/**
	 * 
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#list(net.swift.module.other.ExaQueryBean, net.swift.common.ReturnMessage)
	 */
	public List list(NotAdvForm theForm,  ReturnMessage msg) 
	{
		List list = null;

		Connection cn = null;

		try
		{
			cn = DbcpPool.getConnection();
			
			NotAdvServiceSqlMysql servSql = new NotAdvServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();

			Object[] fields2 = new Object[3];
			
			fields2[0] = theForm.getQryNtype();
			fields2[1] = theForm.getQryNsort();
			fields2[2] = theForm.getQryNsortID();

			String sql = servSql.getCountSql2();

			/**
			 * 根据SQL执行结果计算分页相关信息
			 */
			PageCtr page = theForm.getPage();
			page.setTotalNum(bSqlServ.dbCount(cn, sql, fields2));
			page.caculate();

			//取得FORM中传入的查询参数
			Object[] fields = new Object[5];
			
			fields[0] = theForm.getQryNtype();
			fields[1] = theForm.getQryNsort();
			fields[2] = theForm.getQryNsortID();
			fields[3] = page.getPos()-1;
			fields[4] = page.getPageSize();
			
			sql = servSql.getRecbyPageSql();
	
			list = bSqlServ.dbRead(cn, sql, fields, new DbNotAdvService());
			
		    DbcpPool.returnConnection(cn);
		    
		} catch(Exception ex) 
		{
			/**
			 * 记录相关日志
			 */
			logger.error(ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
			
		} finally {
			DbcpPool.returnConnection(cn);
		}		
		
		return list;
	}
	
	/**
	 * 取得社区 业委/物业的公告 通知
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#list(net.swift.module.other.ExaQueryBean, net.swift.common.ReturnMessage)
	 */
	public List shequlist(NotAdvForm theForm,  ReturnMessage msg) 
	{
		List list = null;

		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			NotAdvServiceSqlMysql servSql = new NotAdvServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();

			//取得FORM中传入的查询参数
			Object[] fields = new Object[3];
			
			fields[0] = theForm.getQryVillageID();
			fields[1] = theForm.getQryVillageID();
			fields[2] = theForm.getPage().getPageSize();
			
			String sql = servSql.getRecbyShequSql();
	
			list = bSqlServ.dbRead(cn, sql, fields, new DbNotAdvService());
			
		    DbcpPool.returnConnection(cn);
		    
		} catch(Exception ex) 
		{
			/**
			 * 记录相关日志
			 */
			logger.error(ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
			
		} finally {
			DbcpPool.returnConnection(cn);
		}		
		
		return list;
	}	
	/**
	 * 分组取得 公告 通知 前10条记录
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#list(net.swift.module.other.ExaQueryBean, net.swift.common.ReturnMessage)
	 */
	public List listbyGroup(NotAdvForm theForm,  ReturnMessage msg) 
	{
		List list = null;

		Connection cn = null;

		try
		{
			cn = DbcpPool.getConnection();
			
			NotAdvServiceSqlMysql servSql = new NotAdvServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();

			Object[] fields2 = new Object[9];
			
			String arr[] = theForm.getQryNtype().split(",");
			if(arr.length > 0){
				int len = arr.length;
				for(int i=0; i<len; i++){
					
					fields2[i] = arr[i];
				}
			}
			fields2[6] = theForm.getQryNsort();
			fields2[7] = theForm.getQryNsortID();
			fields2[8] = theForm.getPage().getPageSize();
			
			String sql = servSql.getByGroupSql();
	
			list = bSqlServ.dbRead(cn, sql, fields2, new DbNotAdvService());
			
		    DbcpPool.returnConnection(cn);
		    
		} catch(Exception ex) 
		{
			/**
			 * 记录相关日志
			 */
			logger.error(ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
			
		} finally {
			DbcpPool.returnConnection(cn);
		}		
		
		return list;
	}	
	/**
	 * 
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#list(net.swift.module.other.ExaQueryBean, net.swift.common.ReturnMessage)
	 */
	public List adlist(NotAdvForm theForm,  ReturnMessage msg) 
	{
		List list = new Vector();

		Connection cn = null;
		Statement stmt=null;
		ResultSet rs=null;
		try
		{
			cn = DbcpPool.getConnection();
			
			NotAdvServiceSqlMysql servSql = new NotAdvServiceSqlMysql();
			
			StringBuffer sb = new StringBuffer(" where 1=1 ");

			String QryContent = theForm.getQryContent().replaceAll(GlbFinal.SQLINjection, " ");
			if(!QryContent.equals("")){
				
				sb.append(" and Content like '%");
				sb.append(QryContent);
				sb.append("%' ");
			}

			String QryNtype = theForm.getQryNtype().replaceAll(GlbFinal.SQLINjection, " ");
			String arr[] = QryNtype.split(",");

			if(!QryNtype.equals("")){
				
				StringBuffer tmp = new StringBuffer("");
				int len = arr.length;
				sb.append(" and (");
				for(int i=0; i<len;i++){
					
					tmp.append(" Ntype = '");
					tmp.append(arr[i]);
					tmp.append("' or");
				}
				sb.append(tmp.substring(0, tmp.length() - 2));
				sb.append(") ");
			}
			
			String QryNsort = theForm.getQryNsort().replaceAll(GlbFinal.SQLINjection, " ");
			
			if(!QryNsort.equals("")){
				
				sb.append(" and Nsort = '");
				sb.append(QryNsort);
				sb.append("' ");
			}
			if(theForm.getQryNsortID() > 0){
				
				sb.append(" and NsortID = ");
				sb.append(theForm.getQryNsortID());
				sb.append(" ");
			}
			if(theForm.getQrySeqID() > 0){
				
				sb.append(" and seqID = ");
				sb.append(theForm.getQrySeqID());
				sb.append(" ");
			}
			
			if(theForm.getFollID() > 0){
				
				sb.append(" and FollID = ");
				sb.append(theForm.getFollID());
				sb.append(" ");
			}

			sb.append(" Order by SeqID desc, FollID ");
			
			//查询记录数
			stmt = cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
			String sql = servSql.getCountSql1();

			logger.debug(sql+sb.toString());
			
			rs=stmt.executeQuery(sql+sb.toString());
			int nRows = 0;
			if (rs.next())
	           nRows = rs.getInt("COUNT");
			else
			{
	            rs.close();
	            stmt.close();
	            DbcpPool.returnConnection(cn);
			    return list;
			}
			/**
			 * 根据SQL执行结果计算分页相关信息
			 */
			PageCtr page = theForm.getPage();
			page.setTotalNum(nRows);
			page.caculate();

			sb.append(" limit ");
			sb.append(page.getPos()-1);
			sb.append(", ");
			sb.append(page.getPageSize());
			
			 //取记录
			 sql = servSql.getRecSql();
			 logger.debug(sql+sb.toString());
			 DbNotAdvService dbuser = new DbNotAdvService();
			 
			 rs=stmt.executeQuery(sql+sb.toString());
			 while (rs.next())
			 {
				try
				{
					Object obj = dbuser.readSqlResultRecord(rs);
					if (obj != null) list.add(obj);
				}
				catch (Throwable t)
				{
					logger.error(t.getMessage());
				}		
			 }
			 rs.close();
			 stmt.close();
		     DbcpPool.returnConnection(cn);

		} catch(Exception ex) 
		{
			/**
			 * 记录相关日志
			 */
			logger.error(ex.getMessage());
			try {
				if (rs != null)
					rs.close();
				if (stmt != null)
					stmt.close();
				DbcpPool.returnConnection(cn);
			} catch (Exception ex1) {
				ex1.printStackTrace();
			}			
	    }finally {
			try {
				if (rs != null)
					rs.close();
				if (stmt != null)
					stmt.close();
			} catch (Exception ex) {
				ex.printStackTrace();
			}			
			DbcpPool.returnConnection(cn);
		}		
		return list;
	}		

	/**
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#get(net.swift.db.tab_paramnostro, net.swift.common.ReturnMessage)
	 */
	public int getMaxFollID(int seqID,ReturnMessage msg) 
	{
		Connection cn = null;
		int follID = 0;
		try
		{
			cn = DbcpPool.getConnection();
			List list = null;

			//取得FORM中传入的查询参数
			Object[] fields = new Object[1];
			
			fields[0] = seqID;			
			
			NotAdvServiceSqlMysql servSql = new NotAdvServiceSqlMysql();			
			BasicSqlService  bSqlServ = new BasicSqlService();
			
			String sql = servSql.getMaxFollIDSql();			
					
			list = bSqlServ.dbRead(cn, sql, fields, new DbNotAdvService());
			
			if(list.size() ==0){
				common.setAppFailMsg(msg , " 取主记录失败，请检查！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				
				return follID;				
			}
			
			BaseNotAdv base = (BaseNotAdv)list.get(0);
				
			follID = base.getFollID() + 1;
			
			DbcpPool.returnConnection(cn);
			return follID;
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return follID;
	}
	
	/**
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#get(net.swift.db.tab_paramnostro, net.swift.common.ReturnMessage)
	 */
	public void get(NotAdvForm theForm, ReturnMessage msg) 
	{
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			List list = null;

			//取得FORM中传入的查询参数
			Object[] fields = new Object[2];
			
			fields[0] = theForm.getSeqID();			
			fields[1] = theForm.getFollID();			
			
			NotAdvServiceSqlMysql servSql = new NotAdvServiceSqlMysql();			
			BasicSqlService  bSqlServ = new BasicSqlService();
			
			String sql = servSql.getbykeySql();			
					
			list = bSqlServ.dbRead(cn, sql, fields, new DbNotAdvService());
			if(list.size() ==0){
				common.setAppFailMsg(msg , " 取记录失败，请检查！");
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;				
			}
			
			BaseNotAdv base = (BaseNotAdv)list.get(0);
				
			BeanUtils.copyProperties(theForm, base);
			
			DbcpPool.returnConnection(cn);
			return;
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return ;
	}
	
	/**
	 * 投诉会员，先添加投诉记录，然后修改会员状态
	 * @see net.IUserbasicService.module.other.IUserService#add(net.swift.common.ReturnMessage)
	 */
	public void toususer(NotAdvForm theForm, ReturnMessage msg) 
	{
		
		Connection cn = null;
		
		try
		{
			cn = DbcpPool.getConnection();
	
			DbcpPool.beginTran(cn);
			
			//如果是互动投诉，则修改被投诉短信状态为已读
			if(theForm.getTsfr().equals(GlbFinal.TS_FRMSG)){
				
				MessageServiceImpl msgservice = new MessageServiceImpl();
				MessageForm msgform = new MessageForm();
				
				msgform.setSeqID(theForm.getTsfrID());
				msgform.setStatus(GlbFinal.WEBMSG_READ);
				
				msgservice.updsts(cn, msgform, msg);
				if(msg.getErrCode() != 0){
					
					return;
				}
				
				MsgcontServiceImpl msgcontservice = new MsgcontServiceImpl();
				MsgcontForm msgcontform = new MsgcontForm();
				
				msgcontform.setMsgID(msgform.getMsgID());
				
				msgcontservice.get(cn, msgcontform, msg);
				if(msg.getErrCode() != 0){
					
					return;
				}
				StringBuffer sb = new StringBuffer(" ");
				
				sb.append(theForm.getContent());
				sb.append("<br>被投诉内容：<br>");
				sb.append(msgcontform.getMsg());
				
				theForm.setContent(sb.toString().trim());				
				
			}else
			//如果是留言投诉，则修改被投诉留言状态为关闭
			if(theForm.getTsfr().equals(GlbFinal.TS_FRLIUYAN)){
				
				NotAdvForm notadvform = new NotAdvForm();
				
				notadvform.setSeqID(theForm.getTsfrID());
				notadvform.setFollID(0);
				notadvform.setStatus(GlbFinal.STS_CLOSE);
				
				updsts(cn, notadvform, msg);
				if(msg.getErrCode() != 0){
					return;
				}
				StringBuffer sb = new StringBuffer(" ");
				
				sb.append(theForm.getContent());
				sb.append("<br>被投诉内容：<br>");
				sb.append(notadvform.getContent());
				
				theForm.setContent(sb.toString().trim());
			}
			
			//添加投诉记录
			add( cn,  theForm,  msg);
			if(msg.getErrCode() != 0){
				return;
			}

			//修改会员状态
			UsersServiceImpl userservice = new UsersServiceImpl();
			UsersForm userform = new UsersForm();
			
			userform.setUserID(theForm.getNsortID());
			userform.setStatus(GlbFinal.USERSTS_CHECKING);
			
			userservice.updateuser(cn, userform, msg);
			if(msg.getErrCode() != 0){
				return;
			}
			
			
			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);
			DbcpPool.returnConnection(cn);
			
		} catch(Exception ex) 
		{
			common.setAppFailMsg(msg , ex.getMessage());
			logger.error("System error , param get about operlog" + ex);
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return;
	}
	
	/**
	 * 添加表中
	 * @see net.IUserbasicService.module.other.IUserService#add(net.swift.common.ReturnMessage)
	 */
	public void add(NotAdvForm theForm, ReturnMessage msg) 
	{
		
		Connection cn = null;
		
		try
		{
			cn = DbcpPool.getConnection();
	
			DbcpPool.beginTran(cn);
			
			add( cn,  theForm,  msg);
			if(msg.getErrCode() != 0){
				return;
			}
			
			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);
			DbcpPool.returnConnection(cn);
			
		} catch(Exception ex) 
		{
			common.setAppFailMsg(msg , ex.getMessage());
			logger.error("System error , param get about operlog" + ex);
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return;
	}

	/**
	 * 添加表中
	 * @see net.IUserbasicService.module.other.IUserService#add(net.swift.common.ReturnMessage)
	 */
	public void add(Connection cn, NotAdvForm theForm, ReturnMessage msg) 
	{
		
		
		try
		{
			
			NotAdvServiceSqlMysql servSql = new NotAdvServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			
			int follID = 0;
			//取跟帖序号
			if(theForm.getSeqID() > 0){
				
				follID = getMaxFollID( theForm.getSeqID(), msg);
				if(msg.getErrCode() != 0){
					return;
				}
				theForm.setFollID(follID);
			}else{
				theForm.setSeqID(SequenceMgr.generateSeq(GlbFinal.SEQ_INITDATE, GlbFinal.SEQ_NOTADVID));
			}
			//保存附件一
			if(theForm.getFilepath() != null&&!theForm.getFilepath().getFileName().equals("")){
				
				FilesForm fileForm = new FilesForm();
				fileForm.setFormFile(theForm.getFilepath());
				fileForm.setF_info(theForm.getTitle());
				fileForm.setF_Zip(GlbFinal.ZIP_600);
				
				FilesServiceImpl fileservice = new FilesServiceImpl();
				
				fileservice.add(cn, fileForm, msg);
				if(msg.getErrCode() != 0){
					return;
				}
				theForm.setF_ID(fileForm.getF_ID());
			}			
	        String intro = StringUtil.htmlTotxt(theForm.getContent());
	        
	        int len = intro.length();
	        if(len > 254){
	        	len = 254;
	        }
	        theForm.setIntroduction(intro.substring(0,len));
			
			//取得FORM中传入的查询参数
			Object[] fields = new Object[16];
						
			fields[0] = theForm.getSeqID();			//	序号
			fields[1] = theForm.getFollID();		//	跟贴序号
			fields[2] = theForm.getNtype();			//	类型
			fields[3] = theForm.getTitle();			//	标题
			fields[4] = theForm.getIntroduction();	//	简介
			fields[5] = theForm.getContent();		//	发贴/跟贴内容
			fields[6] = theForm.getF_ID();			//	附件ID
			fields[7] = theForm.getNsort();			//	所属板块
			fields[8] = theForm.getNsortID();		//	板块内容ID
			fields[9] = theForm.getUp();			//	是否置顶
			fields[10] = theForm.getStatus();		//	状态
			fields[11] = theForm.getAttachcnt();	//	点击次数
			fields[12] = theForm.getReplycnt();		//	回复次数
			fields[13] = theForm.getUserID();		//	会员ID
			fields[14] = theForm.getIP();			//	用户IP
			fields[15] = DatetimeUtil.getDatetime();	//	最后修改时间
			
			String sql = servSql.getInsertSql();
						
			boolean  res = bSqlServ.dbWrite(cn, sql, fields);
			if(!res){
				common.setAppFailMsg(msg , " 保存数据失败！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;
			}
			
			//如果是跟帖 ，更新帖子回复数
			if(theForm.getFollID() > 0){
				
				NotAdvForm notadvform = new NotAdvForm();
				
				notadvform.setSeqID(theForm.getSeqID());
				notadvform.setFollID(0);
				notadvform.setReplycnt(1);
				
				updsts(cn, notadvform, msg);
				if(msg.getErrCode() !=0){
					
					return;
				}
			}
			
			
		} catch(Exception ex) 
		{
			common.setAppFailMsg(msg , ex.getMessage());
			logger.error("System error , param get about operlog" + ex);
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
		}
		
		return;
	}

	/**
	 * 删除一条指定记录
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void delete(NotAdvForm theForm, ReturnMessage msg) 
	{
		
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			DbcpPool.beginTran(cn);

			//取得FORM中传入的查询参数
			Object[] fields = new Object[2];
			
			fields[0] = theForm.getSeqID();
			fields[1] = theForm.getFollID();
			
			NotAdvServiceSqlMysql servSql = new NotAdvServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			String sql = servSql.getDeleteSql();
			
								
			boolean  res = bSqlServ.dbWrite(cn, sql, fields);
			if(!res){
				common.setAppFailMsg(msg , " 删除记录失败，请检查！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;
			}
			
			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);
			DbcpPool.returnConnection(cn);
			return;
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return ;
	}
	/**
	 * 删除公告及所有回复信息
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void delall(NotAdvForm theForm, ReturnMessage msg) 
	{
		
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			DbcpPool.beginTran(cn);

			NotAdvServiceSqlMysql servSql = new NotAdvServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			
			//取得原信息
			//取得FORM中传入的查询参数
			Object[] fields2 = new Object[2];
			
			fields2[0] = theForm.getSeqID();			
			fields2[1] = 0;			
			
			String sql = servSql.getbykeySql();			
					
			List list = bSqlServ.dbRead(cn, sql, fields2, new DbNotAdvService());
			if(list.size() ==0){
				common.setAppFailMsg(msg , " 取记录失败，请检查！");
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;				
			}
			
			BaseNotAdv base = (BaseNotAdv)list.get(0);
				
			BeanUtils.copyProperties(theForm, base);
			
			
			//删除记录和回复信息
			Object[] fields = new Object[1];
			
			fields[0] = theForm.getSeqID();
			
			sql = servSql.getDelbyseqIDSql();
								
			boolean  res = bSqlServ.dbWrite(cn, sql, fields);
			if(!res){
				common.setAppFailMsg(msg , " 删除记录失败，请检查！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;
			}
			
			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);
			DbcpPool.returnConnection(cn);
			return;
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return ;
	}
	/**
	 * 更新一条指定记录
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void updsts(NotAdvForm theForm, ReturnMessage msg) 
	{
		
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			DbcpPool.beginTran(cn);
			
			updsts(cn, theForm, msg);
			if(msg.getErrCode() != 0){
				return;
			}

			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);
			DbcpPool.returnConnection(cn);
			return;
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
				
		return ;
	}
	/**
	 * 更新一条指定记录
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void updsts(Connection cn, NotAdvForm theForm, ReturnMessage msg) 
	{
		
		try
		{
			List list = null;

			NotAdvServiceSqlMysql servSql = new NotAdvServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();

			//取得FORM中传入的查询参数
			Object[] fields = new Object[2];
			
			fields[0] = theForm.getSeqID();			
			fields[1] = theForm.getFollID();			
			
			String sql = servSql.getbykeySql();			
					
			list = bSqlServ.dbRead(cn, sql, fields, new DbNotAdvService());
			if(list.size() == 0){
				common.setAppFailMsg(msg , "取主记录失败！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;				
			}
			
			BaseNotAdv base = (BaseNotAdv)list.get(0);
			
			if(theForm.getUp().equals("")){
				theForm.setUp(base.getUp());
			}
			if(theForm.getStatus().equals("")){
				theForm.setStatus(base.getStatus());
			}
				
			Object[] fields2 = new Object[6];
			
			fields2[0] = theForm.getUp();			//	是否置顶
			fields2[1] = theForm.getStatus();		//	状态
			fields2[2] = base.getAttachcnt() + theForm.getAttachcnt();	//	点击次数
			fields2[3] = base.getReplycnt() + theForm.getReplycnt();		//	回复次数
			fields2[4] = theForm.getSeqID();			//	序号
			fields2[5] = theForm.getFollID();		//	跟贴序号
		
			sql = servSql.getUpdstsSql();			
			
			boolean  res = bSqlServ.dbWrite(cn, sql, fields2);
			if(!res){
				common.setAppFailMsg(msg , " 更新记录失败，请检查！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;
			}
			BeanUtils.copyProperties(theForm, base);
			
			return;
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
		}
				
		return ;
	}	
	/**
	 * 更新一条指定记录
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void update(NotAdvForm theForm, ReturnMessage msg) 
	{
		
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			DbcpPool.beginTran(cn);
			List list = null;

			NotAdvServiceSqlMysql servSql = new NotAdvServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			
			//取得FORM中传入的查询参数
			Object[] fields = new Object[2];
			
			fields[0] = theForm.getSeqID();			
			fields[1] = theForm.getFollID();			
			
			String sql = servSql.getbykeySql();			
					
			list = bSqlServ.dbRead(cn, sql, fields, new DbNotAdvService());		
			if(list.size() == 0){
				common.setAppFailMsg(msg , "取原记录失败！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;				
			}
			
			BaseNotAdv base = (BaseNotAdv)list.get(0);
	
			//保存附件一
			if(theForm.getFilepath() != null && !theForm.getFilepath().getFileName().equals("")){
				
				FilesForm fileForm = new FilesForm();
				fileForm.setFormFile(theForm.getFilepath());
				fileForm.setF_info(theForm.getTitle());
				fileForm.setF_Zip(GlbFinal.ZIP_600);
				
				FilesServiceImpl fileservice = new FilesServiceImpl();
				
				fileservice.add(cn, fileForm, msg);
				if(msg.getErrCode() != 0){
					return;
				}
				theForm.setF_ID(fileForm.getF_ID());
			}			
	        String intro = StringUtil.htmlTotxt(theForm.getContent());
	        int len = intro.length();
	        if(len > 254){
	        	len = 254;
	        }
	        theForm.setIntroduction(intro.substring(0,len));
						
			Object[] fields2 = new Object[16];
			
			fields2[0] = theForm.getNtype();			//	类型
			fields2[1] = theForm.getTitle();			//	标题
			fields2[2] = theForm.getIntroduction();	//	简介
			fields2[3] = theForm.getContent();		//	发贴/跟贴内容
			fields2[4] = theForm.getF_ID();			//	附件ID
			fields2[5] = theForm.getNsort();			//	所属板块
			fields2[6] = theForm.getNsortID();		//	板块内容ID
			fields2[7] = theForm.getUp();			//	是否置顶
			fields2[8] = theForm.getStatus();		//	状态
			fields2[9] = theForm.getAttachcnt();		//	点击次数
			fields2[10] = theForm.getReplycnt();		//	回复次数
			fields2[11] = theForm.getUserID();		//	会员ID
			fields2[12] = theForm.getIP();			//	用户IP
			fields2[13] = DatetimeUtil.getDatetime();	//	最后修改时间			
			fields2[14] = theForm.getSeqID();			//	序号
			fields2[15] = theForm.getFollID();		//	跟贴序号
		
			sql = servSql.getUpdateSql();			
			
			boolean  res = bSqlServ.dbWrite(cn, sql, fields2);
			if(!res){
				common.setAppFailMsg(msg , " 更新记录失败，请检查！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;
			}

			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);
			DbcpPool.returnConnection(cn);
			return;
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
				
		return ;
	}
	
	/**
	 * 删除一条投诉建议
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void delete(JgShenqingForm theForm, ReturnMessage msg) 
	{
		
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			DbcpPool.beginTran(cn);

			//取得FORM中传入的查询参数
			Object[] fields = new Object[2];
			
			fields[0] = theForm.getSeqID();
			fields[1] = theForm.getFollID();
			
			NotAdvServiceSqlMysql servSql = new NotAdvServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			String sql = servSql.getDeleteSql();
			
								
			boolean  res = bSqlServ.dbWrite(cn, sql, fields);
			if(!res){
				common.setAppFailMsg(msg , " 删除记录失败，请检查！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;
			}
			
			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);
			DbcpPool.returnConnection(cn);
			return;
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return ;
	}
	
	/**
	 * 删除一条投诉建议
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void delete1(JgShenqingForm theForm, ReturnMessage msg) 
	{
		
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			DbcpPool.beginTran(cn);

			//取得FORM中传入的查询参数
			Object[] fields = new Object[1];
			
			fields[0] = theForm.getSeqID();
			
			NotAdvServiceSqlMysql servSql = new NotAdvServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			String sql = servSql.getDeleteSql1();
			
								
			boolean  res = bSqlServ.dbWrite(cn, sql, fields);
			if(!res){
				common.setAppFailMsg(msg , " 删除记录失败，请检查！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;
			}
			
			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);
			DbcpPool.returnConnection(cn);
			return;
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return ;
	}
}
